package com.dlwx.parttimetalent.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;
import android.widget.TextView;

import com.dlwx.parttimetalent.R;
import com.dlwx.parttimetalent.bean.IcomeHisBean;
import com.dlwx.parttimetalent.ui.IncomeDetailActivity;
import com.github.jdsjlzx.ItemDecoration.DividerDecoration;
import com.github.jdsjlzx.interfaces.OnItemClickListener;
import com.github.jdsjlzx.recyclerview.LRecyclerView;
import com.github.jdsjlzx.recyclerview.LRecyclerViewAdapter;

import java.util.List;

/**
 * Created by Administrator on 2017/11/21.
 */

public class IncomeHisAdapter extends ListBaseAdapter<IcomeHisBean.BodyBean> {
    private  Context context;
    public IncomeHisAdapter(Context context) {
        super(context);
        this.context=context;
    }

    @Override
    public int getLayoutId() {
        return  R.layout.item_income_title;
    }

    @Override
    public void onBindItemHolder(SuperViewHolder holder, int position) {
        IcomeHisBean.BodyBean bean = getDataList().get(position);
        TextView tv_time=holder.getView(R.id.tv_time);
        LRecyclerView recyclerView=holder.getView(R.id.recyclerView);
        tv_time.setText(bean.getTime());
        List<IcomeHisBean.BodyBean.ListdataBean> lists = bean.getListdata();
        if(lists!=null){

            initRecyclerView(recyclerView,lists);
        }
        }

    private void initRecyclerView(LRecyclerView recyclerView, final List<IcomeHisBean.BodyBean.ListdataBean> lists) {
        recyclerView.setLayoutManager(new LinearLayoutManager(context));
        final IncomeHisItemAdapter mAdapter = new IncomeHisItemAdapter(context);
        mAdapter.setDataList(lists);
        LRecyclerViewAdapter lRecyclerViewAdapter = new LRecyclerViewAdapter(mAdapter);
        //divider
        DividerDecoration divider = new DividerDecoration.Builder(context)
                .setHeight(R.dimen.size_1)
//                .setPadding(R.dimen.divider_padding)
                .setColorResource(R.color.bg)
                .build();
        recyclerView.setHasFixedSize(true);
        recyclerView.addItemDecoration(divider);
        recyclerView.setAdapter(lRecyclerViewAdapter);
        recyclerView.setLoadMoreEnabled(false);
        recyclerView.setPullRefreshEnabled(false);
        lRecyclerViewAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                Intent i=new Intent(context,IncomeDetailActivity.class);
                i.putExtra("id",lists.get(position).getCapitalid()+"");
                context.startActivity(i);
            }
        });
    }

}
